package Presentacion;

import Clases.Empleado;
import Control.ControlEmpleado;
import de.javasoft.plaf.synthetica.SyntheticaLookAndFeel;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.text.NumberFormatter;

public class ManejoEmpleado extends javax.swing.JFrame {

    ControlEmpleado controlE = ControlEmpleado.obtenerInstancia();
    private static ManejoEmpleado instancia = null;
    Long numeroEmpleado = null;
    private ImageIcon iconoError;
    private Empleados refEmpleados = null;
    NumberFormat numberFormat = (DecimalFormat) DecimalFormat.getNumberInstance();
    NumberFormat numberFormatCodigo = (NumberFormat) NumberFormat.getNumberInstance();
    NumberFormat numberFormatCedula = (NumberFormat) NumberFormat.getNumberInstance();

    private ManejoEmpleado() {
        initComponents();
        inicioTooltops();
        txtBuscarEmpleado.setToolTipText("Ingrese la cédula o código del empleado.");
    }

    private void ocultarLabels() {
        labelNombreApellidos.setVisible(false);
        labelNacionalidad.setVisible(false);
        labelCedula.setVisible(false);
        labelCodigo.setVisible(false);
        labelCorreo.setVisible(false);
        labelFechaNacimiento.setVisible(false);
        labelDireccion.setVisible(false);
        labelTelefono.setVisible(false);
        labelFechaIngreso.setVisible(false);
        labelPuesto.setVisible(false);
        labelSalario.setVisible(false);
        labelBanco.setVisible(false);
        labelCuenta.setVisible(false);
    }

    private void inicioTooltops() {
        iconoError = new ImageIcon(getClass().getResource("/Imagenes/warning.png"));

        labelNombreApellidos.setIcon(iconoError);
        labelNombreApellidos.setToolTipText("Debe escribir el nombre y los dos apellidos correctamente.");

        labelNacionalidad.setIcon(iconoError);
        labelNacionalidad.setToolTipText("Debe escribir una nacionalidad válida.");

        labelCedula.setIcon(iconoError);
        labelCedula.setToolTipText("Debe escribir una cédula o número de pasaporte válidos.");

        labelCodigo.setIcon(iconoError);
        labelCodigo.setToolTipText("Debe escribir un código de empleado.");

        labelCorreo.setIcon(iconoError);
        labelCorreo.setToolTipText("Debe escribir un correo válido.");

        labelFechaNacimiento.setIcon(iconoError);
        labelFechaNacimiento.setToolTipText("Debe escribir una fecha de nacimiento válida y debe ser mayor de 15 años.");

        labelDireccion.setIcon(iconoError);
        labelDireccion.setToolTipText("Debe escribir una dirección de domicilio.");

        labelTelefono.setIcon(iconoError);
        labelTelefono.setToolTipText("Debe escribir un número de teléfono válido.");

        labelFechaIngreso.setIcon(iconoError);
        labelFechaIngreso.setToolTipText("Debe escribir una fecha de ingreso válida.");

        labelPuesto.setIcon(iconoError);
        labelPuesto.setToolTipText("Debe escribir un puesto.");

        labelSalario.setIcon(iconoError);
        labelSalario.setToolTipText("Debe escribir un salario válido.");

        labelBanco.setIcon(iconoError);
        labelBanco.setToolTipText("Debe seleccionar un banco.");

        labelCuenta.setIcon(iconoError);
        labelCuenta.setToolTipText("Debe ingresar un número de cuenta válido mayor a 13 dígitos.");

        ocultarLabels();
    }

    public static ManejoEmpleado obtenerInstancia() {
        if (instancia == null) {
            instancia = new ManejoEmpleado();
        }
        return instancia;
    }

    public void init(Empleados em, String cedulaEmpleado) {
        setTitle("Ingresar Empleado");
        setLocationRelativeTo(null);
        UIManager.removeAuxiliaryLookAndFeel(UIManager.getLookAndFeel());
        SwingUtilities.updateComponentTreeUI(this);
        try {
            UIManager.removeAuxiliaryLookAndFeel(UIManager.getLookAndFeel());
            SyntheticaLookAndFeel.setWindowsDecorated(false);
            UIManager.setLookAndFeel("de.javasoft.plaf.synthetica.SyntheticaAluOxideLookAndFeel");
            SwingUtilities.updateComponentTreeUI(this);

        } catch (Exception ex) {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        this.limpiar();
        this.NumberFormat();
        this.refEmpleados = em;
        if (!cedulaEmpleado.equals("0")) {
            this.llenarCampos(cedulaEmpleado);
        }

        this.setVisible(true);
    }

    public void NumberFormat() {
        numberFormat.setMaximumIntegerDigits(7);
        numberFormat.setMinimumFractionDigits(0);
        numberFormat.setMinimumIntegerDigits(2);
        NumberFormatter nfr = new NumberFormatter(numberFormat);
        this.txtSalario.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(nfr));

        numberFormatCodigo.setMinimumIntegerDigits(1);
        numberFormatCodigo.setMaximumIntegerDigits(4);
        NumberFormatter nfrCodigo = new NumberFormatter(numberFormatCodigo);
        //this.txtCodigo.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(nfrCodigo));

        numberFormatCedula.setMinimumIntegerDigits(7);
        //numberFormatCedula.setMaximumIntegerDigits(12);

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        txtApellido1 = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        txtApellido2 = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        txtNacionalidad = new javax.swing.JTextField();
        txtCedula = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txtDireccion = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        txtCorreo = new javax.swing.JTextField();
        DateChooserNacimiento = new com.toedter.calendar.JDateChooser();
        jLabel24 = new javax.swing.JLabel();
        txtTel1 = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        txtCodigo = new javax.swing.JTextField();
        labelNombreApellidos = new javax.swing.JLabel();
        labelNacionalidad = new javax.swing.JLabel();
        labelCedula = new javax.swing.JLabel();
        labelCodigo = new javax.swing.JLabel();
        labelCorreo = new javax.swing.JLabel();
        labelFechaNacimiento = new javax.swing.JLabel();
        labelDireccion = new javax.swing.JLabel();
        labelTelefono = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        txtTel2 = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        txtTel3 = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel19 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txtPuesto = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        txtSalario = new javax.swing.JFormattedTextField();
        jLabel18 = new javax.swing.JLabel();
        ComboBoxOpcionPago = new javax.swing.JComboBox();
        jLabel17 = new javax.swing.JLabel();
        txtNumCuenta = new javax.swing.JFormattedTextField();
        jLabel22 = new javax.swing.JLabel();
        ComboBoxBanco = new javax.swing.JComboBox();
        DateChooserIngreso = new com.toedter.calendar.JDateChooser();
        labelFechaIngreso = new javax.swing.JLabel();
        labelPuesto = new javax.swing.JLabel();
        labelSalario = new javax.swing.JLabel();
        labelBanco = new javax.swing.JLabel();
        labelCuenta = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        txtBuscarEmpleado = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 32767));
        filler2 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 32767));
        filler3 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 32767));
        filler4 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 32767));
        filler5 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));
        jButton2 = new javax.swing.JButton();

        jLabel1.setText("jLabel1");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(1100, 400));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos Personales", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel9.setText("Nombre ");

        jLabel20.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel20.setText("Apellido Paterno");

        jLabel21.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel21.setText("Apellido Materno");

        jLabel14.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel14.setText("Nacionalidad:");
        jLabel14.setToolTipText("");

        jLabel13.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel13.setText("Identificación:");

        jLabel15.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel15.setText("Fecha de Nacimiento: ");

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel8.setText("Correo electrónico:");

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel11.setText("Dirección:");

        DateChooserNacimiento.setToolTipText("");
        DateChooserNacimiento.setDateFormatString("dd-MM-yyyy");

        jLabel24.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel24.setText("Teléfono Casa: ");

        jLabel23.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel23.setText("Código:");

        labelNombreApellidos.setText("x");
        labelNombreApellidos.setMaximumSize(new java.awt.Dimension(24, 24));
        labelNombreApellidos.setMinimumSize(new java.awt.Dimension(22, 22));
        labelNombreApellidos.setPreferredSize(new java.awt.Dimension(22, 22));

        labelNacionalidad.setText("x");
        labelNacionalidad.setMaximumSize(new java.awt.Dimension(24, 24));
        labelNacionalidad.setMinimumSize(new java.awt.Dimension(22, 22));
        labelNacionalidad.setPreferredSize(new java.awt.Dimension(22, 22));

        labelCedula.setText("x");
        labelCedula.setMaximumSize(new java.awt.Dimension(24, 24));
        labelCedula.setMinimumSize(new java.awt.Dimension(22, 22));
        labelCedula.setPreferredSize(new java.awt.Dimension(22, 22));

        labelCodigo.setText("x");
        labelCodigo.setMaximumSize(new java.awt.Dimension(24, 24));
        labelCodigo.setMinimumSize(new java.awt.Dimension(22, 22));
        labelCodigo.setPreferredSize(new java.awt.Dimension(22, 22));

        labelCorreo.setText("x");
        labelCorreo.setMaximumSize(new java.awt.Dimension(24, 24));
        labelCorreo.setMinimumSize(new java.awt.Dimension(22, 22));
        labelCorreo.setPreferredSize(new java.awt.Dimension(22, 22));

        labelFechaNacimiento.setText("x");
        labelFechaNacimiento.setMaximumSize(new java.awt.Dimension(24, 24));
        labelFechaNacimiento.setMinimumSize(new java.awt.Dimension(22, 22));
        labelFechaNacimiento.setPreferredSize(new java.awt.Dimension(22, 22));

        labelDireccion.setText("x");
        labelDireccion.setMaximumSize(new java.awt.Dimension(24, 24));
        labelDireccion.setMinimumSize(new java.awt.Dimension(22, 22));
        labelDireccion.setPreferredSize(new java.awt.Dimension(22, 22));

        labelTelefono.setText("x");
        labelTelefono.setMaximumSize(new java.awt.Dimension(24, 24));
        labelTelefono.setMinimumSize(new java.awt.Dimension(22, 22));
        labelTelefono.setPreferredSize(new java.awt.Dimension(22, 22));

        jLabel25.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel25.setText("Teléfono Celular: ");

        jLabel26.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel26.setText("Teléfono Emergencia: ");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel15)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(DateChooserNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(labelFechaNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addGap(18, 18, 18)
                                .addComponent(txtCorreo, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(labelCorreo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel24)
                                    .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel25)
                                    .addComponent(jLabel26))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(txtTel1, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(labelTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(txtTel2, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtTel3, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 312, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(18, 18, 18)
                        .addComponent(labelDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtApellido1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel20))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel21)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(txtApellido2, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(labelNombreApellidos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtNacionalidad, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(labelNacionalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel23)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel13)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtCedula, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(13, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel20)
                    .addComponent(jLabel21))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtApellido1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtApellido2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelNombreApellidos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(txtNacionalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelNacionalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(txtCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel23)
                    .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(txtCorreo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelCorreo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel15)
                            .addComponent(DateChooserNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(labelFechaNacimiento, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel24)
                    .addComponent(txtTel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel25)
                    .addComponent(txtTel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtTel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel26)))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Otros Datos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

        jLabel19.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel19.setText("Fecha de Ingreso: ");

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel10.setText("Puesto: ");

        jLabel16.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel16.setText("Salario base mensual:");

        txtSalario.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtSalarioKeyPressed(evt);
            }
        });

        jLabel18.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel18.setText("Opción de pago: ");

        ComboBoxOpcionPago.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Efectivo", "Cuenta Bancaria" }));
        ComboBoxOpcionPago.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ComboBoxOpcionPagoActionPerformed(evt);
            }
        });

        jLabel17.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel17.setText("Número de Cuenta:");

        txtNumCuenta.setEditable(false);

        jLabel22.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel22.setText("Banco afiliado : ");

        ComboBoxBanco.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Ninguno", "Bancredito", "Banco Popular" }));
        ComboBoxBanco.setEnabled(false);

        DateChooserIngreso.setDateFormatString("dd-MM-yyyy");

        labelFechaIngreso.setText("x");
        labelFechaIngreso.setMaximumSize(new java.awt.Dimension(24, 24));
        labelFechaIngreso.setMinimumSize(new java.awt.Dimension(22, 22));
        labelFechaIngreso.setPreferredSize(new java.awt.Dimension(22, 22));

        labelPuesto.setText("x");
        labelPuesto.setMaximumSize(new java.awt.Dimension(24, 24));
        labelPuesto.setMinimumSize(new java.awt.Dimension(22, 22));
        labelPuesto.setPreferredSize(new java.awt.Dimension(22, 22));

        labelSalario.setText("x");
        labelSalario.setMaximumSize(new java.awt.Dimension(24, 24));
        labelSalario.setMinimumSize(new java.awt.Dimension(22, 22));
        labelSalario.setPreferredSize(new java.awt.Dimension(22, 22));

        labelBanco.setText("x");

        labelCuenta.setText("x");
        labelCuenta.setMaximumSize(new java.awt.Dimension(24, 24));
        labelCuenta.setMinimumSize(new java.awt.Dimension(22, 22));
        labelCuenta.setPreferredSize(new java.awt.Dimension(22, 22));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel18)
                                    .addComponent(jLabel22))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(ComboBoxBanco, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(ComboBoxOpcionPago, 0, 108, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(labelBanco)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel17)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtNumCuenta, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(labelCuenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel16)
                                    .addComponent(jLabel10))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(txtPuesto, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtSalario, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(labelSalario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(labelPuesto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addContainerGap(22, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel19)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(DateChooserIngreso, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(labelFechaIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(246, 246, 246))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel19)
                    .addComponent(DateChooserIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelFechaIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtPuesto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(labelPuesto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel10))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(txtSalario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelSalario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(ComboBoxOpcionPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel17)
                        .addComponent(txtNumCuenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(labelCuenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel22)
                        .addComponent(ComboBoxBanco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(labelBanco)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButton1.setText("Cancelar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("Buscar: ");

        txtBuscarEmpleado.setToolTipText("Ingrese la cédula o código del empleado.");
        txtBuscarEmpleado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtBuscarEmpleadoActionPerformed(evt);
            }
        });

        jButton3.setText("Buscar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Crear o Modificar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton2.setText("Limpiar Formulario");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(257, 257, 257)
                .addComponent(filler2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtBuscarEmpleado, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(223, 223, 223)
                        .addComponent(filler4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(639, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(310, 310, 310)
                        .addComponent(jButton4)
                        .addGap(18, 18, 18)
                        .addComponent(jButton1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(filler1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(filler5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addComponent(filler3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(filler2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtBuscarEmpleado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(106, 106, 106)
                                .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(filler5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(90, 90, 90)
                                .addComponent(filler3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(46, 46, 46)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton4)
                            .addComponent(jButton1))
                        .addGap(2, 2, 2))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addComponent(filler4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        ocultarLabels();
        this.limpiar();
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
      this.crear();
    }//GEN-LAST:event_jButton4ActionPerformed
    public void limpiar() {
        txtNombre.setText("");
        txtApellido1.setText("");
        txtApellido2.setText("");
        txtNacionalidad.setText("");
        txtCedula.setText("");
        txtCedula.setEnabled(true);
        txtCedula.setEditable(true);
        txtCodigo.setText("");
        txtTel1.setText("");
        txtTel2.setText("");
        txtTel3.setText("");
        DateChooserNacimiento.setDate(null);
        DateChooserIngreso.setDate(null);
        txtCorreo.setText("");
        txtDireccion.setText("");
        txtPuesto.setText("");
        txtSalario.setText("");
        txtSalario.setValue(null);
        txtNumCuenta.setText("");
        txtBuscarEmpleado.setText("");
        numeroEmpleado = null;
        this.ComboBoxOpcionPago.setSelectedIndex(0);
        this.ComboBoxBanco.setSelectedIndex(0);
        this.ocultarLabels();

    }

    private boolean validacionAgregar() {
        ocultarLabels();
        boolean itsOk = true;

        String nombre = txtNombre.getText();
        String apellido1 = txtApellido1.getText();

        if (nombre.isEmpty() || apellido1.isEmpty() /*|| apellido2.isEmpty()*/) {
            itsOk = false;
            labelNombreApellidos.setVisible(true);
        }

        String nacionalidad = txtNacionalidad.getText();
        if (nacionalidad.isEmpty()) {
            itsOk = false;
            labelNacionalidad.setVisible(true);
        }

        String cedula = txtCedula.getText();

        //rango de cedula, de 7 digitos a 11, tomando en cuenta cedulas extrangeras y cedulas nacionales
       /* if (cedula.length() < 7 || cedula.length() > 12) {
         itsOk = false;
         labelCedula.setVisible(true);
         }*/
        try {
            if (cedula.equals("")) {
                labelCedula.setVisible(true);
                itsOk = false;
            } else {
                Integer cedulaNumerico = txtCedula.getText().trim().isEmpty() ? null : numberFormatCedula.parse(txtCedula.getText()).intValue();
                if ((String.valueOf(cedulaNumerico)).length() < 7 || (String.valueOf(cedulaNumerico)).length() > 12) {
                    labelCedula.setVisible(true);
                    itsOk = false;
                }
            }
        } catch (Exception e) {
            labelCedula.setVisible(true);
            itsOk = false;
        }

        String codigoInt = txtCodigo.getText();
        /*if (codigo.isEmpty()) {
         itsOk = false;
         labelCodigo.setVisible(true);
         }*/

        try {
            if (codigoInt.equals("")) {
                labelCodigo.setVisible(true);
                itsOk = false;
            } else {
                Integer codigoNumerico = txtCodigo.getText().trim().isEmpty() ? null : numberFormatCodigo.parse(txtCodigo.getText()).intValue();
                if (codigoNumerico < 1) {
                    labelCodigo.setVisible(true);
                    itsOk = false;
                }
            }
        } catch (Exception e) {
            labelCodigo.setVisible(true);
            itsOk = false;
        }

        String correo = txtCorreo.getText();
        if (!correo.isEmpty()) {
            if (!correo.contains("@") || !correo.contains(".")) {
                itsOk = false;
                labelCorreo.setVisible(true);
            }
        }

        Date fechaHoy = new Date();
        int comparacion = 0;

        Date nacimiento = DateChooserNacimiento.getDate();
        if (nacimiento != null) {
            int edad = calcularEdad(nacimiento);
            //ver problema con el metodo calcularEdad, no es exacto
            if (edad < 15) {
                itsOk = false;
                labelFechaNacimiento.setVisible(true);
            }
        }
        try {
            String num = txtTel1.getText();
            String numSinGuion = "";
            for (int i = 0; i < num.length(); i++) {
                if (!(num.charAt(i) == '-')) {
                    numSinGuion = numSinGuion + num.charAt(i);
                }
            }
            if (numSinGuion.equals("")) {
                itsOk = false;
                labelTelefono.setVisible(true);
            } else {
                Integer numInt = Integer.parseInt(numSinGuion);
                if ((String.valueOf(numInt)).length() < 8) {
                    itsOk = false;
                    labelTelefono.setVisible(true);
                }
            }
        } catch (Exception e) {
            itsOk = false;
            labelTelefono.setVisible(true);
        }
        Date ingreso = DateChooserIngreso.getDate();

        try {
            comparacion = fechaHoy.compareTo(ingreso);
        } catch (Exception e) {
            comparacion = 0;
        }
        //si comparacion es menor a 0 es porque el parametro es posterior al que ejecuta el metodo, 0 es igual.
        if (ingreso == null || comparacion <= 0) {
            itsOk = false;
            labelFechaIngreso.setVisible(true);
        }

        String puesto = txtPuesto.getText();
        if (puesto.isEmpty()) {
            itsOk = false;
            labelPuesto.setVisible(true);
        }

        String salario = txtSalario.getText();
        try {
            if (salario.equals("")) {
                labelSalario.setVisible(true);
                itsOk = false;
            } else {
                Integer salarioEntero = txtSalario.getText().trim().isEmpty() ? null : numberFormat.parse(txtSalario.getText()).intValue();
                if (salarioEntero < 1000) {
                    labelSalario.setVisible(true);
                    itsOk = false;
                }
            }
        } catch (Exception e) {
            labelSalario.setVisible(true);
            itsOk = false;
        }
        String opcionPago = (String) ComboBoxOpcionPago.getSelectedItem();
        if (!"Efectivo".equals(opcionPago)) {
            String opcionBanco = (String) ComboBoxBanco.getSelectedItem();
            String numCuenta = txtNumCuenta.getText();
            if ("Ninguno".equals(opcionBanco)) {
                labelBanco.setVisible(true);
                itsOk = false;
            }
            if (numCuenta.length() < 13) {
                labelCuenta.setVisible(true);
                itsOk = false;
            }
        }
        return itsOk;
    }

    //Metodo sacado de https://sites.google.com/a/upao.edu.pe/hwongu/mundo-java/tips-de-codificacion/calculo-de-la-edad
    public static int calcularEdad(Date fechaNacimiento) {
        try {
            Calendar nacimiento = new GregorianCalendar();
            Calendar fechaHoyCalendar = new GregorianCalendar();
            int age = 0;
            int factor = 0;//para saber si aun no a celebrado el cumpleanos
            Date fechaHoyDate = new Date();
            nacimiento.setTime(fechaNacimiento);
            fechaHoyCalendar.setTime(fechaHoyDate);
            if (fechaHoyCalendar.get(Calendar.MONTH) <= nacimiento.get(Calendar.MONTH)) {
                if (fechaHoyCalendar.get(Calendar.MONTH) == nacimiento.get(Calendar.MONTH)) {
                    if (fechaHoyCalendar.get(Calendar.DATE) > nacimiento.get(Calendar.DATE)) {
                        factor = -1;
                    }
                } else {
                    factor = -1;
                }
            }
            age = (fechaHoyCalendar.get(Calendar.YEAR) - nacimiento.get(Calendar.YEAR)) + factor;
            return age;
            //el metodo no considera los anos de los dias bisiestos, significa que debe tener 18 anos y unos dias para calificar como mayor de edad
        } catch (Exception e) {
            return -1;
        }
    }

    public void llenarCampos(String empleado) {
        if (!empleado.equals("")) {
            Empleado empleadoCedula = controlE.getEmpleadoCedula(Long.valueOf(empleado));
            Empleado empleadoCodigo = controlE.getEmpleadoCodigo(Long.valueOf(empleado));
            Empleado empleadoEncontrado = null;
            if (empleadoCedula != null) {
                empleadoEncontrado = empleadoCedula;
            } else {
                empleadoEncontrado = empleadoCodigo;
            }
            if (empleadoEncontrado != null) { // si  es distinto de null es xq si existe
                //llenar campos cn la info
                txtNombre.setText(empleadoEncontrado.getNombre());
                txtApellido1.setText(empleadoEncontrado.getApellido1());
                if (empleadoEncontrado.getApellido2() != null) {
                    txtApellido2.setText(empleadoEncontrado.getApellido2());
                }
                txtNacionalidad.setText(empleadoEncontrado.getNacionalidad());
                txtCedula.setText(String.valueOf(empleadoEncontrado.getCedula()));
                txtCodigo.setText(String.valueOf(empleadoEncontrado.getCodigo()));
                txtCedula.setEditable(false);
                txtTel1.setText(String.valueOf(empleadoEncontrado.getTelefonoCasa()));
                if (empleadoEncontrado.getTelefonoCelular() != null) {
                    txtTel2.setText(String.valueOf(empleadoEncontrado.getTelefonoCelular()));
                }
                if (empleadoEncontrado.getTelefonoEmergencias() != null) {
                    txtTel3.setText(String.valueOf(empleadoEncontrado.getTelefonoEmergencias()));
                }
                if (empleadoEncontrado.getFechaNacimiento() != null) {
                    DateChooserNacimiento.setDate(empleadoEncontrado.getFechaNacimiento());
                }
                if (empleadoEncontrado.getCorreoElectronico() != null) {
                    txtCorreo.setText(empleadoEncontrado.getCorreoElectronico());
                }
                if (empleadoEncontrado.getDireccion() != null) {
                    txtDireccion.setText(empleadoEncontrado.getDireccion());
                }
                DateChooserIngreso.setDate(empleadoEncontrado.getFechaIngreso());
                txtPuesto.setText(empleadoEncontrado.getPuesto());
                txtSalario.setText(String.valueOf(empleadoEncontrado.getSalario()));
                ComboBoxOpcionPago.setSelectedItem(empleadoEncontrado.getOpcionPago());
                ComboBoxBanco.setSelectedItem(empleadoEncontrado.getBandoAfiliado());
                if (empleadoEncontrado.getNumCuenta() != null) {
                    txtNumCuenta.setText(String.valueOf(empleadoEncontrado.getNumCuenta()));
                }
                numeroEmpleado = empleadoEncontrado.getNumEmpleado();
            } else {
                JOptionPane.showMessageDialog(null, "El empleado no existe", "Mensaje", JOptionPane.ERROR_MESSAGE);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Por favor ingrese el código o cédula del empleado en el campo de texto", "Mensaje", JOptionPane.ERROR_MESSAGE);
        }
    }
    void crear(){
      int confirmado = JOptionPane.showConfirmDialog(null, "¿Está seguro que todos los datos del empleado son correctos?");
        if (JOptionPane.OK_OPTION == confirmado) {
            if (validacionAgregar()) {
                try {
                    String nombre = txtNombre.getText().trim();
                    String apellido1 = txtApellido1.getText().trim();
                    String apellido2 = txtApellido2.getText().trim();
                    String nacionalidad = txtNacionalidad.getText().trim();
                    Long cedula = txtCedula.getText().trim().isEmpty() ? null : Long.valueOf(txtCedula.getText());
                    Long codigo = txtCodigo.getText().trim().isEmpty() ? null : Long.valueOf(txtCodigo.getText());
                    Integer tel1 = txtTel1.getText().trim().isEmpty() ? null : Integer.valueOf(txtTel1.getText());
                    Integer tel2 = txtTel2.getText().trim().isEmpty() ? null : Integer.valueOf(txtTel2.getText());
                    Integer tel3 = txtTel3.getText().trim().isEmpty() ? null : Integer.valueOf(txtTel3.getText());
                    Date nacimiento = DateChooserNacimiento.getDate();
                    //java.sql.Date sqlDate1 = new java.sql.Date((nacimiento.getTime()));
                    java.sql.Date fechaNacimiento = nacimiento == null ? null : new java.sql.Date(nacimiento.getTime());
                    String correo = txtCorreo.getText();
                    String direccion = txtDireccion.getText();
                    Date ingreso = this.DateChooserIngreso.getDate();
                    java.sql.Date fechaIngreso = ingreso == null ? null : new java.sql.Date(ingreso.getTime());
                    String puesto = txtPuesto.getText();
                    Integer salario = txtSalario.getText().trim().isEmpty() ? null : numberFormat.parse(txtSalario.getText()).intValue();
                    String opcionPago = (String) ComboBoxOpcionPago.getSelectedItem();
                    String banco = "";
                    String numCuenta = "";
                    if (!"Efectivo".equals(opcionPago)) {
                        banco = (String) ComboBoxBanco.getSelectedItem();
                        numCuenta = txtNumCuenta.getText();
                    }

                    Empleado empleadoNuevo = new Empleado(cedula, codigo, nombre, apellido1, apellido2, nacionalidad, fechaNacimiento, correo, direccion, fechaIngreso, puesto, salario, opcionPago, banco, numCuenta, fechaIngreso, null, tel1, tel2, tel3);
                    boolean resultado = controlE.insertarOActualizarEmpleado(empleadoNuevo);
                    if (!resultado) {
                        JOptionPane.showMessageDialog(null, "Error al agregar o modificar el empleado,asegure de que todos los campos sean correctos", "Mensaje", JOptionPane.ERROR_MESSAGE);
                    } else {
                        JOptionPane.showMessageDialog(null, "Empleado ingresado o modificado correctamente", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                        this.limpiar();
                        ocultarLabels();
                        dispose();
                    }
                } catch (Exception e) {
                    System.out.println(e.getMessage());
                    System.out.println(e.getCause());
                    JOptionPane.showMessageDialog(null, "Hubo un error capturando la información.", "Mensaje", JOptionPane.ERROR_MESSAGE);
                }
            }
            this.refEmpleados.llenarTablaEmpleados();
        }
    }
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        this.limpiar();
        String identificador = txtBuscarEmpleado.getText();
        this.llenarCampos(identificador);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void txtBuscarEmpleadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtBuscarEmpleadoActionPerformed
    }//GEN-LAST:event_txtBuscarEmpleadoActionPerformed

    private void ComboBoxOpcionPagoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ComboBoxOpcionPagoActionPerformed
        String seleccionado = (String) ComboBoxOpcionPago.getSelectedItem();
        if (seleccionado.equals("Cuenta Bancaria")) {
            ComboBoxBanco.setEnabled(true);
            txtNumCuenta.setEditable(true);
        } else {
            ComboBoxBanco.setEnabled(false);
            txtNumCuenta.setEditable(false);
        }
    }//GEN-LAST:event_ComboBoxOpcionPagoActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        this.limpiar();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void txtSalarioKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSalarioKeyPressed
          int key = evt.getKeyCode();
        if (key == evt.VK_ENTER) {
            this.crear();
        }
    }//GEN-LAST:event_txtSalarioKeyPressed

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;

                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ManejoEmpleado.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ManejoEmpleado.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ManejoEmpleado.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ManejoEmpleado.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        JFrame.setDefaultLookAndFeelDecorated(true);
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ManejoEmpleado().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox ComboBoxBanco;
    private javax.swing.JComboBox ComboBoxOpcionPago;
    private com.toedter.calendar.JDateChooser DateChooserIngreso;
    private com.toedter.calendar.JDateChooser DateChooserNacimiento;
    private javax.swing.Box.Filler filler1;
    private javax.swing.Box.Filler filler2;
    private javax.swing.Box.Filler filler3;
    private javax.swing.Box.Filler filler4;
    private javax.swing.Box.Filler filler5;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel labelBanco;
    private javax.swing.JLabel labelCedula;
    private javax.swing.JLabel labelCodigo;
    private javax.swing.JLabel labelCorreo;
    private javax.swing.JLabel labelCuenta;
    private javax.swing.JLabel labelDireccion;
    private javax.swing.JLabel labelFechaIngreso;
    private javax.swing.JLabel labelFechaNacimiento;
    private javax.swing.JLabel labelNacionalidad;
    private javax.swing.JLabel labelNombreApellidos;
    private javax.swing.JLabel labelPuesto;
    private javax.swing.JLabel labelSalario;
    private javax.swing.JLabel labelTelefono;
    private javax.swing.JTextField txtApellido1;
    private javax.swing.JTextField txtApellido2;
    private javax.swing.JTextField txtBuscarEmpleado;
    private javax.swing.JTextField txtCedula;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtCorreo;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JTextField txtNacionalidad;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JFormattedTextField txtNumCuenta;
    private javax.swing.JTextField txtPuesto;
    private javax.swing.JFormattedTextField txtSalario;
    private javax.swing.JTextField txtTel1;
    private javax.swing.JTextField txtTel2;
    private javax.swing.JTextField txtTel3;
    // End of variables declaration//GEN-END:variables
}
